package redis

import (
	"github.com/gomodule/redigo/redis"
	"naio/config"
	"time"
)

type BaseRedisClient struct {
	Pool *redis.Pool
}

var Client *BaseRedisClient

func Setup() {
	_RedisClient := new(BaseRedisClient)
	_RedisClient.Pool = &redis.Pool{
		MaxIdle: 256,
		MaxActive: 0,
		IdleTimeout: time.Duration(120),
		Dial: func() (redis.Conn, error){
			return redis.Dial(
				"tcp",
					config.Config.RedisHost+":"+config.Config.RedisPort,
					redis.DialReadTimeout(time.Duration(1000)*time.Millisecond),
					redis.DialWriteTimeout(time.Duration(1000)*time.Millisecond),
					redis.DialConnectTimeout(time.Duration(1000)*time.Millisecond),
					redis.DialDatabase(config.Config.RedisDb),
					redis.DialPassword(config.Config.RedisAuth),
				)
		},
	}
	Client = _RedisClient
}

//con := redis.Client.Pool.Get()
//if err := con.Err(); err != nil {
//	panic(err)
//}
//res, err := con.Do("set", "name", "刘佳依")
//if err != nil {
//  panic(err)
//}
//fmt.Printf("res::%#v", res)
//
//reply, err := red.String(con.Do("get", "name"))
//if err != nil{
// fmt.Println("get失败")
// return
//}
//fmt.Printf("reply::%#v", reply)
